package com.hubei.control;

import com.hubei.service.UserService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by IntelliJ IDEA.
 * User: 曾婉君
 * Date: 2025/6/25 Time: 16:53
 */
@WebServlet("/user_delete.action")
public class UserDeleteControl extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String id = request.getParameter("id");
        UserService service = UserService.getInstance();
        int rows = service.deleteUser(id);
        if (rows == 0){
            request.setAttribute("delErr","数据删除失败，请联系开发商！");
        }else {
            response.sendRedirect("./user_list.action");
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
